using System;
using System.Collections.Generic;

namespace Matrix.Configuration.Events
{
    /// <summary>
    /// 配置变更事件参数
    /// </summary>
    public class ConfigurationChangedEventArgs : EventArgs
    {
        /// <summary>
        /// 配置键
        /// </summary>
        public string Key { get; set; } = string.Empty;

        /// <summary>
        /// 命名空间
        /// </summary>
        public string Namespace { get; set; } = string.Empty;

        /// <summary>
        /// 旧值
        /// </summary>
        public object? OldValue { get; set; }

        /// <summary>
        /// 新值
        /// </summary>
        public object? NewValue { get; set; }

        /// <summary>
        /// 值类型
        /// </summary>
        public Type ValueType { get; set; } = typeof(object);

        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; }

        /// <summary>
        /// 变更来源
        /// </summary>
        public ConfigurationChangeSource Source { get; set; }

        /// <summary>
        /// 变更者
        /// </summary>
        public string? ChangedBy { get; set; }
    }

    /// <summary>
    /// 类型化配置变更事件参数
    /// </summary>
    /// <typeparam name="T">配置类型</typeparam>
    public class ConfigurationChangedEventArgs<T> : ConfigurationChangedEventArgs
    {
        /// <summary>
        /// 类型化旧值
        /// </summary>
        public T? TypedOldValue => OldValue is T oldValue ? oldValue : default;

        /// <summary>
        /// 类型化新值
        /// </summary>
        public T? TypedNewValue => NewValue is T newValue ? newValue : default;
    }
}